package io.esirong.anim;

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;

/**
 * 旋转动画
 */
@SuppressWarnings("all")
public class RotateAnim {
    /**
     * 根据当前的状态来旋转箭头。
     *
     * @param view
     * @param flag
     */
    public static void rotateArrow(View view, boolean flag) {
        float pivotX = view.getWidth() / 2f;
        float pivotY = view.getHeight() / 2f;
        float fromDegrees = 0f;
        float toDegrees = 0f;
        // flag为true则向上
        if (flag) {
            fromDegrees = 180f;
            toDegrees = 360f;
        } else {
            fromDegrees = 0f;
            toDegrees = 180f;
        }
        //旋转动画效果   参数值 旋转的开始角度  旋转的结束角度  pivotX x轴伸缩值
        RotateAnimation animation = new RotateAnimation(fromDegrees, toDegrees,
                pivotX, pivotY);
        //该方法用于设置动画的持续时间，以毫秒为单位
        animation.setDuration(200);
        //设置重复次数
        //animation.setRepeatCount(int repeatCount);
        //动画终止时停留在最后一帧
        animation.setFillAfter(true);
        //启动动画
        view.startAnimation(animation);
    }

    /**
     * 缩放
     */
    public static void scale(View view) {
        final long duration = 200;
        ScaleAnimation scaleAnimation = new ScaleAnimation(
                0.0F, 1.0f, 0.0F, 1.0f,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        
        scaleAnimation.setDuration(duration);
        scaleAnimation.setFillEnabled(true);
        scaleAnimation.setFillAfter(true);

        view.startAnimation(scaleAnimation);

    }
}
